package com.xiaoyu.commonlib.ui.widget;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.ScrollView;

/**
 * Created by jk on 2018/9/28.
 */
public class BaseScrollView extends ScrollView {
    private OnScrollChangedListener mListener;
    public BaseScrollView(Context context) {
        super(context);
    }

    public BaseScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BaseScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onScrollChanged(int x, int y, int oldx, int oldy) {
        super.onScrollChanged(x, y, oldx, oldy);
        if (mListener != null){
            mListener.onScrollChanged(this,x, y, oldx, oldy);
        }
    }

    @Override
    protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
        return 0;
    }

    /**
     * 滑动视图的监听
     * Created by jk on 2017/12/26.
     */

    public interface OnScrollChangedListener {

        /**
         *
         * @param scrollView 要监听的滑动视图
         * @param x x轴坐标
         * @param y  y轴坐标
         * @param oldx 上一个x轴坐标
         * @param oldy 上一个y轴坐标
         */
        void onScrollChanged(ScrollView scrollView, int x, int y, int oldx, int oldy);
    }

    public void setOnScrollChangedListener(OnScrollChangedListener listener){
        this.mListener = listener;
    }
}
